﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
//帮助函数
namespace help
{
    public static class utils
    {
        
        public static void AddContextMenu(this RichTextBox rtb)
        {
            if (rtb.ContextMenuStrip == null)
            {
//                 ContextMenuStrip cms = new ContextMenuStrip { ShowImageMargin = false };
//                 ToolStripMenuItem tsmiCut = new ToolStripMenuItem(Resources.Extensions_AddContextMenu_Cut);
//                 tsmiCut.Click += (sender, e) => rtb.Cut();
//                 cms.Items.Add(tsmiCut);
//                 ToolStripMenuItem tsmiCopy = new ToolStripMenuItem(Resources.Extensions_AddContextMenu_Copy);
//                 tsmiCopy.Click += (sender, e) => rtb.Copy();
//                 cms.Items.Add(tsmiCopy);
//                 ToolStripMenuItem tsmiPaste = new ToolStripMenuItem(Resources.Extensions_AddContextMenu_Paste);
//                 tsmiPaste.Click += (sender, e) => rtb.Paste();
//                 cms.Items.Add(tsmiPaste);
//                 rtb.ContextMenuStrip = cms;
            }
        }

        //通过标签头和尾获取标签中间的文本内容
        public static string GetContent(string str, string startTag, string endTag)
        {
            string result = string.Empty;
            string pattern = "(?<=" + startTag + ")[\\s\\S]*?(?=" + endTag + ")";
            Regex reg = new Regex(pattern, RegexOptions.Singleline | RegexOptions.IgnoreCase);
            Match match = reg.Match(str);
            if (match.Success)
            {
                result = match.Value;
            }
            return result;
        }
    }
}
